package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.ZxKemuKey;
import cn.stylefeng.guns.sys.modular.system.model.params.ZxKemuKeyParam;
import cn.stylefeng.guns.sys.modular.system.model.result.ZxKemuKeyResult;
import cn.stylefeng.guns.sys.modular.system.service.ZxKemuKeyService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 控制器
 *
 * @author jiangge
 * @Date 2021-01-07 15:04:25
 */
@Controller
@RequestMapping("/dgdzxKemuKey")
public class DgdZxKemuKeyController extends BaseController {

    private Long pinpai = 1417361607353536514L;

    private String PREFIX = "/modular/system/dgdzxKemuKey";

    @Autowired
    private ZxKemuKeyService zxKemuKeyService;

    /**
     * 跳转到主页面
     *
     * @author jiangge
     * @Date 2021-01-07
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/zxKemuKey.html";
    }

    /**
     * 新增页面
     *
     * @author jiangge
     * @Date 2021-01-07
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/zxKemuKey_add.html";
    }

    /**
     * 编辑页面
     *
     * @author jiangge
     * @Date 2021-01-07
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/zxKemuKey_edit.html";
    }

    /**
     * 新增接口
     *
     * @author jiangge
     * @Date 2021-01-07
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ZxKemuKeyParam zxKemuKeyParam) {
        zxKemuKeyParam.setPinpai(pinpai);
        ResponseData responseData=this.zxKemuKeyService.add(zxKemuKeyParam);
        return responseData;
    }

    /**
     * 编辑接口
     *
     * @author jiangge
     * @Date 2021-01-07
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ZxKemuKeyParam zxKemuKeyParam) {
        zxKemuKeyParam.setPinpai(pinpai);
        this.zxKemuKeyService.update(zxKemuKeyParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author jiangge
     * @Date 2021-01-07
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ZxKemuKeyParam zxKemuKeyParam) {
        this.zxKemuKeyService.delete(zxKemuKeyParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author jiangge
     * @Date 2021-01-07
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ZxKemuKeyParam zxKemuKeyParam) {
        ZxKemuKey detail = this.zxKemuKeyService.getDetailById(zxKemuKeyParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author jiangge
     * @Date 2021-01-07
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ZxKemuKeyParam zxKemuKeyParam) {
        zxKemuKeyParam.setPinpai(pinpai);
        return this.zxKemuKeyService.findPageBySpec(zxKemuKeyParam);
    }

    /**
     * 门店报销单-直接添加报销单需要的关键字
     *
     * @param zxKemuKeyParam
     * @return
     */
    @ResponseBody
    @RequestMapping("/getAllKemuKeyList")
    public ResponseData getAllKemuKeyList(ZxKemuKeyParam zxKemuKeyParam) {
        zxKemuKeyParam.setPinpai(pinpai);
        List<ZxKemuKeyResult> allKemuKeyList = this.zxKemuKeyService.getAllKemuKeyList(zxKemuKeyParam);
        return ResponseData.success(allKemuKeyList);
    }

    @RequestMapping("/setJgc")
    @ResponseBody
    public ResponseData setJgc(ZxKemuKeyParam para) {
        String ids = para.getIds();
        String[] idsArr=  ids.split(",");
        for(String id:idsArr){
            this.zxKemuKeyService.updateJgc(id,para.getIsJgc());
        }
        return ResponseData.success();
    }
}


